<template>
	<view class="vip">

		<view class="box">
			<view class="infoli">
				<view class="left">
					提现金额
				</view>
				<view class="right">
					<input type="number" placeholder="请输入金额" v-model="num">
				</view>
			</view>
			<view class="infoli">
				<view class="left">
					验证码
				</view>
				<view class="right">
					<input type="number" placeholder="请输入验证码" v-model="code">
					<text class="code" @click="SendCode" v-show="is_send">获取验证码</text>
					<text class="code" v-show="!is_send">{{time}}s</text>
				</view>
			</view>
		</view>

		<view class="tips">
			可用余额 : ￥{{user.balance_1}}
		</view>
		<view>
			<button class="btn" :loading="loading" :disabled="loading" @click="withdraw">提现</button>
		</view>
	</view>
</template>

<script>
	import {
		commonParam,
		UserInfo,
		sendCode
	} from "@/api/api.js"
	import {
		withdraw
	} from "@/api/user.js"
	export default {
		data() {
			return {
				range: [],
				type: '',
				username: '',
				num: '',
				code: '',
				password: '',
				loading: false,
				user: [],
				balance: '0.000',
				time: 60,
				timer: '',
				is_send: true,
			}
		},
		onLoad() {
			// this.commonParam()
			this.UserInfo()
		},
		methods: {
			SendCode() {
				this.is_send = false
				this.time = 60
				sendCode({
					phone: this.user.phone
				}).then(res => {
					uni.$showMsg(res.msg)
					if (res.code == 0) {
						this.timer = setInterval(() => {
							this.time--;
							if (this.time < 0) {
								clearInterval(this.timer)
								this.is_send = true
							}
						}, 1000)
					}
				})
			},
			change(e) {
				this.balance = this.user['balance_' + e]
			},
			UserInfo() {
				UserInfo().then(res => {
					if (res.code == 0) {
						this.user = res.data.user
					}
				})
			},
			commonParam() {
				commonParam().then(res => {
					if (res.code == 0) {
						this.range = res.data.coin
					}
				})
			},
			withdraw() {
				var that = this
				if (that.num == '') {
					return uni.$showMsg('请输入金额')
				}
				that.loading = true
				withdraw({
					num: that.num,
					code: that.code,
				}).then(res => {
					that.loading = false
					uni.$showMsg(res.msg)
					if (res.code == 0) {
						that.num = ''
						that.code = ''
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		padding-top: 10px;
		background: #f2f2f2;
	}

	.uni-select {
		border: 1px solid #eee !important;
		height: 40px !important;
		border-bottom: unset;
	}

	.box {
		width: 96%;
		margin: 0 auto;
		margin-top: 20px;
		background: #fff;
		border-radius: 5px;
		padding: 10px 12px;
		box-sizing: border-box;
		box-shadow: 0 0 5px #d5d5d5;

		.title {
			font-weight: bold;
			font-size: 15px;
		}

		.infoli {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 15px 0;

			.left {
				width: 30%;
				font-weight: bold;
			}

			.right {
				width: 70%;
				position: relative;
				display: flex;
				align-items: center;

				input {
					font-size: 14px;
				}

				.code {
					position: absolute;
					right: 10px;
					top: 50%;
					transform: translate(0, -50%);
					color: #050B18;
				}
			}
		}

		.inputli {
			margin-top: 10px;

			input {
				font-size: 16px;
				padding: 10px 0;
				color: #050B18;
			}
		}
	}

	.tips {
		width: 92%;
		margin: 0 auto;
		color: #777;
		font-size: 12px;
		margin-top: 10px;
	}

	.btn {
		width: 90%;
		color: #fff;
		font-size: 15px;
	}
</style>